package com.ddwl.data.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.data.ChannelConfigAddBo;
import com.ddwl.schema.bo.data.ChannelConfigPageBo;
import com.ddwl.schema.bo.data.ChannelConfigUpdateBo;
import com.ddwl.schema.bo.data.ChannelConfigValidBo;
import com.ddwl.schema.vo.data.ChannelConfigVo;
import com.ddwl.data.service.ChannelConfigService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Author hemiaojun
 * @Date 2020/11/9 14:45
 */
@RestController
@RequestMapping("/channelConfig")
@Api(tags = "渠道配置")
public class ChannelConfigController extends BaseController {

    @Resource
    private ChannelConfigService channelConfigService;

    @PostMapping("/add")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    @ApiOperation("新增渠道配置")
    public RestVo add(@RequestBody @Valid ChannelConfigAddBo bo){
        channelConfigService.add(bo);
        return RestVo.ok();
    }

    @PostMapping("/update")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    @ApiOperation("新增渠道配置")
    public RestVo update(@RequestBody @Valid ChannelConfigUpdateBo bo){
        channelConfigService.update(bo);
        return RestVo.ok();
    }

    @GetMapping("/get/{id}")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    @ApiOperation("获取详情")
    public RestVo<ChannelConfigVo> get(@PathVariable("id") String id){
        return RestVo.ok(channelConfigService.get(id));
    }

    @DeleteMapping("/delete/{id}")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    @ApiOperation("删除渠道配置")
    public RestVo delete(@PathVariable("id") String id){
        channelConfigService.delete(id);
        return RestVo.ok();
    }

    @PostMapping("/page")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    @ApiOperation("渠道配置分页")
    public RestVo<PageVo<ChannelConfigVo>> page(@RequestBody PageBo<ChannelConfigPageBo> pageBo){
        return RestVo.ok(channelConfigService.page(pageBo));
    }

    @PostMapping("/changeValid")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    @ApiOperation("设置是否有效")
    public RestVo changeValid(@RequestBody ChannelConfigValidBo bo){
        channelConfigService.changeValid(bo);
        return RestVo.ok();
    }

    @PostMapping("/changeId")
    @ApiOperation("把id反转成时间戳")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo changeId(){
        channelConfigService.changeId();
        return RestVo.ok();
    }

}
